<template>
  <div class="wrapper" v-if="content.reportContent">
    <div class="title">年度报告内容</div>
    <div class="des" v-html="content.reportContent.replace(/(\r\n|\n|\r)/gm, '<br />')"></div>
    <div class="sub-title" v-if="content.fileVOList && content.fileVOList.length">附件</div>
    <div class="file-list">
      <div class="file-item" v-for="(item, index) in content.fileVOList" :key="index" @click="downloadFile(item)">
        <img src="@/assets/common/file-icon.png" />
        <div class="file-name van-ellipsis">{{ item.fileName }}</div>
      </div>
    </div>
    <van-image-preview v-model="showPreview" :images="images"> </van-image-preview>
  </div>
</template>

<script>
export default {
  props: {
    content: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      previewType: ["jpeg", "gif", "jpg", "png"],
      officType: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
      images: [],
      showPreview: false
    };
  },
  methods: {
    downloadFile(item) {
      let arr = item.fileName.split(".");
      let type = arr[arr.length - 1];
      if (this.previewType.includes(type)) {
        this.images = [item.fileUrl];
        this.showPreview = true;
      } else if (this.officType.includes(type)) {
        window.location.href = item.fileUrl.split("?")[0] + "?response-content-type=application/octet-stream";
      } else {
        window.location.href = item.fileUrl;
      }
    }
  }
};
</script>

<style scoped lang="scss">
.wrapper {
  background: #fff;
  padding: 20px 16px;
  margin-top: 12px;
  border-radius: 8px;
  .title {
    line-height: 22px;
    color: #000;
    font-size: 16px;
    margin-bottom: 12px;
  }
  .des {
    font-size: 14px;
    color: #808080;
    word-break: break-all;
  }
}
.sub-title {
  position: relative;
  margin-top: 16px;
  color: #333333;
  padding-left: 12px;
  &::before {
    content: "";
    position: absolute;
    width: 4px;
    height: 14px;
    top: 3px;
    left: 0;
    border-radius: 1px;
    background: #367fff;
  }
}
.file-list {
  margin-top: 16px;
}
.file-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  background: #fafbfc;
  margin-bottom: 12px;
  padding: 14px 16px;
  img {
    display: block;
    width: 26px;
    margin-right: 12px;
  }
  .file-name {
    color: #2a81e6;
    font-size: 13px;
    line-height: 18px;
  }
}
</style>
